cmake_minimum_required(VERSION 3.5)

project(Qt5TcpServer VERSION 1.0.0 LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找Qt5包
find_package(Qt5 REQUIRED COMPONENTS Core Network)

# 设置自动MOC、RCC、UIC
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 源文件
set(SOURCES
    main.cpp
    tcpserver.cpp
    clientmanager.cpp
    clientconnection.cpp
    threadpool.cpp
)

# 头文件
set(HEADERS
    tcpserver.h
    clientmanager.h
    clientconnection.h
    threadpool.h
)

# 创建可执行文件
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

# 链接Qt库
target_link_libraries(${PROJECT_NAME} 
    Qt5::Core 
    Qt5::Network
)

# 编译选项
target_compile_options(${PROJECT_NAME} PRIVATE
    -Wall
    -Wextra
    -pthread
)

# 链接线程库
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} Threads::Threads)

# 安装规则
install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION bin
)